#include "Uses.h"
#include <iostream>
//debugging and output to check
//testing

using namespace std;

	//intialise the vector
	vector<vector<int>> Uses::stmUseTable = vector<vector<int>>();
	vector<vector<int>> Uses::varUseTable = vector<vector<int>>();

	Uses::Uses() {
	}

	//Uses
	void Uses::setStmUsed(int stmNum, int var){
		if(stmUseTable.size() >= stmNum){
			stmUseTable.at(stmNum - 1).push_back(var);
			
			cout << "Adding Var: " << var << " to TableIndex: " << stmNum -1 << " @ Line " << stmNum << endl;

		}else{
			stmUseTable.push_back(vector<int>());
			stmUseTable.at(stmNum - 1).push_back(var);
			cout << "Inserting new entry " << endl;
			cout << "Adding Var: " << var << " to TableIndex: " << stmNum -1 << " @ Line " << stmNum << endl;
		}
	}

	//this table should look like VarTable but with diff info on 2nd column
	void Uses::setVarUsed(int var, int stmNum){
		if(varUseTable.size() >= var){
			varUseTable.at(var - 1).push_back(stmNum);
			cout << "Adding Var: " << var << " to TableIndex: " << stmNum -1 << " @ Line " << stmNum << endl;
		}else{
			varUseTable.push_back(vector<int>());
			varUseTable.at(var - 1).push_back(stmNum);
			cout << "Inserting new entry at VarUseTable " << endl;
			cout << "Adding Var: " << var << " to TableIndex: " << stmNum -1 << " @ Line " << stmNum << endl;
		}
	}

	vector<int> Uses::getStmUsed(int stmNum){
		if(stmUseTable.size() >= stmNum){
			return stmUseTable.at(stmNum - 1);
		}
		else return vector<int>();
	}

	vector<int> Uses::getVarUsed(int var){
		if(varUseTable.size() >= var){
			return varUseTable.at(var - 1);
		}
		else return vector<int> ();
	}

	bool Uses::isUsed (int stmNum, int var){
		if(stmUseTable.size() >= stmNum){
			if(find(stmUseTable.at(stmNum -1).begin(), stmUseTable.at(stmNum -1).end(), var) != stmUseTable.at(stmNum -1).end()){
				return true;
			}else{
				return false;
			}
		}
		else return false;
	}
